#! /bin/bash

docker stop user relation comment video message favourite common hertz
docker rm user relation comment video message favourite common hertz
docker rmi user relation comment video message favourite common hertz

cd common || exit
go mod init common
go mod tidy
export DUBBO_GO_CONFIG_PATH=conf/dubbogo.yaml
# api
cd api || exit
protoc -I . --go_out . --go-triple_out . *.proto
cd ..
# build
go build cmd/app.go
mv app build/.
cp conf/dubbogo.yaml build/.
# docker
cd build || exit
docker build -t common .
docker run -itd --name common -p 9000:9000 common
cd ..
cd ..

cd comment || exit
go mod init comment
go mod tidy
export DUBBO_GO_CONFIG_PATH=conf/dubbogo.yaml
# api
cd api || exit
protoc -I . --go_out . --go-triple_out . *.proto
cd ..
# build
go build cmd/app.go
mv app build/.
cp conf/dubbogo.yaml build/.
# docker
cd build || exit
docker build -t comment .
docker run -itd --name comment -p 9001:9001 comment
cd ..
cd ..

cd favourite || exit
go mod init favourite
go mod tidy
export DUBBO_GO_CONFIG_PATH=conf/dubbogo.yaml
# api
cd api || exit
protoc -I . --go_out . --go-triple_out . *.proto
cd ..
# build
go build cmd/app.go
mv app build/.
cp conf/dubbogo.yaml build/.
# docker
cd build || exit
docker build -t favourite .
docker run -itd --name favourite -p 9003:9003 favourite
cd ..
cd ..

cd message || exit
go mod init message
go mod tidy
export DUBBO_GO_CONFIG_PATH=conf/dubbogo.yaml
# api
cd api || exit
protoc -I . --go_out . --go-triple_out . *.proto
cd ..
# build
go build cmd/app.go
mv app build/.
cp conf/dubbogo.yaml build/.
# docker
cd build || exit
docker build -t message .
docker run -itd --name message -p 9002:9002 message
cd ..
cd ..

cd user || exit
go mod init user
go mod tidy
export DUBBO_GO_CONFIG_PATH=conf/dubbogo.yaml
# api
cd api || exit
protoc -I . --go_out . --go-triple_out . *.proto
cd ..
# build
go build cmd/app.go
mv app build/.
cp conf/dubbogo.yaml build/.
# docker
cd build || exit
docker build -t user .
docker run -itd --name user -p 9520:9520 user
cd ..
cd ..

cd video || exit
go mod init video
go mod tidy
export DUBBO_GO_CONFIG_PATH=conf/dubbogo.yaml
# api
cd api || exit
protoc -I . --go_out . --go-triple_out . *.proto
cd ..
# build
go build cmd/app.go
mv app build/.
cp conf/dubbogo.yaml build/.
# docker
cd build || exit
docker build -t video .
docker run -itd --name video -p 9006:9006 -v /usr/local/upload:/usr/local/upload video
cd ..
cd ..

cd relation || exit
go mod init relation
go mod tidy
export DUBBO_GO_CONFIG_PATH=conf/dubbogo.yaml
# api
cd api || exit
protoc -I . --go_out . --go-triple_out . *.proto
cd ..
# build
go build cmd/app.go
mv app build/.
cp conf/dubbogo.yaml build/.
# docker
cd build || exit
docker build -t relation .
docker run -itd --name relation -p 9004:9004 relation
cd ..
cd ..


cd hertz || exit
go mod init hertz
go mod tidy
# api
cd api || exit
protoc -I . --go_out . --go-triple_out . *.proto
cd ..
# build
go build main.go
mv main build/app
cp conf/dubbogo.yaml build/.
# docker
cd build || exit
docker build -t hertz .
docker run -itd --name hertz -p 8888:8888 hertz
cd ..
cd ..